package com.cloud.gateway.controller.admin.order;


import com.cloud.common.BaseReturn;
import com.cloud.server.domain.order.OrderIntegralDetails;
import com.cloud.server.from.order.OrderIntegralDetailsFrom;
import com.cloud.server.from.user.PraiseFrom;
import com.cloud.server.service.order.OrderIntegralDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liuyuan
 * @since 2021-11-28
 */
@RestController
@CrossOrigin
@RequestMapping("/api/order-integral-details")
public class OrderIntegralDetailsController {
    @Autowired
    OrderIntegralDetailsService orderIntegralDetailsService;

    @RequestMapping("/getOrderIntegralList")
    public BaseReturn getOrderIntegralList(@RequestBody OrderIntegralDetailsFrom orderIntegralDetailsFrom){
        try {
            List<OrderIntegralDetails> byUserId = orderIntegralDetailsService.getByUserId(orderIntegralDetailsFrom);
            return BaseReturn.build("200","查询成功",byUserId);
        } catch (Exception e) {
            e.printStackTrace();
            return BaseReturn.build("500",e.getMessage());
        }

    }
    @RequestMapping("/criticism")
    public BaseReturn criticism(@RequestBody PraiseFrom praiseFrom){
        try {
            boolean result = orderIntegralDetailsService.criticism(praiseFrom);
            if(result){
                return BaseReturn.build("200","扣分成功");
            }else {
                return BaseReturn.build("500","扣分失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return BaseReturn.build("500",e.getMessage());
        }
    }

    @RequestMapping("/praise")
    public BaseReturn praise(@RequestBody PraiseFrom praiseFrom){
        /**
         * 1.生成订单
         * 2.加减总分表
         * */
        try {
            boolean result = orderIntegralDetailsService.praise(praiseFrom);
            if(result){
                return BaseReturn.build("200","加分成功");
            }else {
                return BaseReturn.build("500","加分失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return BaseReturn.build("500",e.getMessage());
        }


    }

}

